<template>
  <div>
    <!-- 导航 -->
    <Nav>
      <el-breadcrumb-item
        slot="nav"
        v-for="(item,index) in breadcrumbList"
        :key="index"
        :to="{ path : item.href}"
      >{{item.name}}</el-breadcrumb-item>
    </Nav>
    <!-- 卡片主题内容 -->
    <el-card>
      <!-- 输入框 -->
      <el-input class="search" placeholder="请输入内容" width="300px" clearable>
        <el-button slot="append" icon="el-icon-search"></el-button>
      </el-input>
      <!-- 表单 -->
      <el-table :data="orderList" style="width: 100%" border stripe>
        <el-table-column label="#" type="index" width="80"></el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="80"></el-table-column>
        <el-table-column prop="pay_status" label="是否付款" width="80">
          <template slot-scope="scope">
            <el-tag type="danger" v-if="scope.row.pay_status === '1'">未付款</el-tag>
            <el-tag type="danger" v-if="scope.row.pay_status === '0'">已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" width="80"></el-table-column>
        <el-table-column prop="create_time" label="下单时间" width="180">
          <template slot-scope="scope">{{scope.row.create_time | dateFormat}}</template>
        </el-table-column>
        <el-table-column label="操作" width="180">
          <template>
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="enditDialogVisible = true"
            ></el-button>
            <el-button type="success" icon="el-icon-location" size="mini" @click="lookPorgress"></el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <!-- <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="querInfo.pagenum"
        :page-sizes="[1, 2, 5, 6]"
        :page-size="querInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>-->
      <Pagination
        :handleSizeChange="handleSizeChange"
        :handleCurrentChange="handleCurrentChange"
        :querInfo="querInfo"
        :total="total"
      ></Pagination>

      <!-- 修改地址对话框 -->
      <el-dialog title="修改地址" :visible.sync="enditDialogVisible" width="50%">
        <el-form
          :model="enditLocalForm"
          :rules="enditLocalFormRules"
          ref="enditLocalFormRef"
          label-width="100px"
        >
          <el-form-item label="省市区/县" prop="address1">
            <el-cascader
              :options="citydata"
              v-model="enditLocalForm.address1"
              expand-trigger="hover"
            ></el-cascader>
          </el-form-item>
          <el-form-item label="详细地址" prop="address2">
            <el-input v-model="enditLocalForm.address2"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="enditDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="enditDialogVisible = false">确 定</el-button>
        </span>
      </el-dialog>

      <!-- 物流进度的对话框 -->
      <el-dialog title="物流进度" :visible.sync="progressDialogVisible" width="50%">
        <el-timeline>
          <el-timeline-item
            v-for="(item, index) in progressInfo"
            :key="index"
            :timestamp="item.time"
          >{{item.context}}</el-timeline-item>
        </el-timeline>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
import Nav from '../nav'
import citydata from './citydata.js'
import Pagination from '../pagination'
export default {
  data() {
    return {
      breadcrumbList: [
        {
          name: '首页',
          href: '/welcome',
        },
        {
          name: '订单管理',
        },
        {
          name: '订单列表',
        },
      ],
      orderList: [],
      querInfo: {
        pagenum: 1,
        pagesize: 5,
      },
      total: 0,
      //   修改地址对话框
      enditDialogVisible: false,
      enditLocalForm: {
        address1: [],
        address2: '',
      },
      enditLocalFormRules: {
        address1: [{ required: true, message: '请选择城市', trigger: 'blur' }],
        address2: [
          { required: true, message: '请输入详细地址', trigger: 'blur' },
        ],
      },
      citydata,
      progressDialogVisible: false,
      progressInfo: [],
    }
  },
  methods: {
    //   获取订单列表数据
    async getOrderList() {
      const { data: res } = await this.$http.get('orders', {
        params: this.querInfo,
      })
      if (res.meta.status !== 200) return this.$message.error('获取失败')
      this.$message.success('获取数据成功')
      this.orderList = res.data.goods
      this.total = res.data.total
    },

    handleSizeChange(newSize) {
      this.querInfo.pagesize = newSize
      this.getOrderList()
    },
    // 点击切换页
    handleCurrentChange(newPage) {
      this.querInfo.pagenum = newPage
      this.getOrderList()
    },

    // 物流进度
    async lookPorgress() {
      const { data: res } = await this.$http.get('/kuaidi/1106975712662')
      if (res.meta.status !== 200) return this.$message.error('获取失败')
      this.progressInfo = res.data
      this.progressDialogVisible = true
    },
  },
  created() {
    this.getOrderList()
  },
  components: {
    Nav,
    Pagination
  },
}
</script>

<style lang="less" scoped>
.search {
  width: 500px;
}
.el-cascader {
  width: 100%;
}
</style>